<template>
  <!--为echarts准备一个具备大小的容器dom-->
  <div id="emain" ref="emain" style="width: 100%; height: 400px"></div>
</template>
<script>
import { totaldata } from '@/api/order';
import echarts from 'echarts'
export default {
  name: 'emdchart',
  data () {
    return {
      charts: '',
    }
  },
  methods: {
    async getData () {
      let res = await totaldata()
      let { xData, amountData, orderData } = res.data
      this.drawPie(xData, amountData, orderData)
    },
    drawPie (xData, amountData, orderData) {
      this.charts = echarts.init(this.$refs.emain)
      this.charts.setOption({
        backgroundColor: '#FFF',
        title: {
          text: '数据统计'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          // data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: xData
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '金额数据',
            type: 'line',
            data: amountData
          },
          {
            name: '订单数据',
            type: 'line',
            data: orderData
          },

        ]
      })
      window.addEventListener('resize', this.charts.resize)
    },
  },
  //调用
  created () {
    this.getData();
  },
  beforeDestroy () {
    window.removeEventListener('resize', this.charts.resize);
  },
}
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
</style>
